package practice;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

class GiveCalendar {
    public LocalDate[] getCalendar(LocalDate date){
        date = date.withDayOfMonth(1);
        int days=date.lengthOfMonth();
        LocalDate dateArrays[]=new LocalDate[days];
        for(int i=0;i<days;i++){
            dateArrays[i]=date.plusDays(i);
        }
        return dateArrays;
    }
}
class MyChrono{
    public  void printChrono(LocalDateTime date){
        LocalDateTime dateEnd=LocalDateTime.now();
        long years=date.until(dateEnd, ChronoUnit.YEARS);
        long months=date.until(dateEnd,ChronoUnit.MONTHS);
        long days=date.until(dateEnd,ChronoUnit.DAYS);
        long hours=date.until(dateEnd,ChronoUnit.HOURS);
        long weeks=date.until(dateEnd,ChronoUnit.WEEKS);
        System.out.println("我的生日为"+date.toString());
        System.out.println("距今已经过去"+years+"年");
        System.out.println(days+"天");
        System.out.println(hours+"小时");
        System.out.println(weeks+"周");
        System.out.println(months+"月");
    }
}

public class MyCalendar {
    public static void main(String[] args) {
        LocalDate birthDate= LocalDate.of(1987,1,31);
        LocalDateTime birthTime=LocalDateTime.of(1987,1,31,0,0,0);
        LocalDate today=LocalDate.now();
        MyChrono chrono=new MyChrono();
        chrono.printChrono( birthTime);
        printCalendar(birthDate);
        printCalendar(today);

    }
    public static void printCalendar(LocalDate date){

        GiveCalendar giveCalendar=new GiveCalendar();
        LocalDate dateArrays[]=giveCalendar.getCalendar(date);
        printNameHead(date);
        for(int i=0;i<dateArrays.length;i++){
            if(i==0){
                printSpace(dateArrays[i].getDayOfWeek());
                System.out.printf("%4d",dateArrays[i].getDayOfMonth());
            }
            else{
                System.out.printf("%4d",dateArrays[i].getDayOfMonth());
            }
            if(dateArrays[i].getDayOfWeek()==DayOfWeek.SATURDAY)
                System.out.println();
        }
    }
    public static void printSpace(DayOfWeek x){
        switch(x){
            case SUNDAY:printSpace(0);
            break;
            case MONDAY:printSpace(1);
            break;
            case TUESDAY:printSpace(2);
            break;
            case WEDNESDAY:printSpace(3);
            break;
            case THURSDAY:printSpace(4);
            break;
            case FRIDAY:printSpace(5);
            break;
            case SATURDAY:printSpace(5);
            break;
        }
    }
    public static void printSpace(int n){
        for(int i=0;i<n;i++){
            System.out.printf("%4s"," ");
        }
    }
    public static void printNameHead(LocalDate date){
        System.out.println(date.getYear()+"年"+date.getMonthValue()+"月日历");
        String name[]={"日","一","二","三","四","五","六"};
        for(int i=0;i<name.length;i++){
            System.out.printf("%3s",name[i]);
        }
        System.out.println();
    }
}
